Skip to content

feat(appkit): add appkit db check - #678

Closed
ditadi wants to merge 401 commits into
stack/database-dev-flow/07-apps-initfrom
stack/database-dev-flow/08-db-check
Closed

ditadi wants to merge 401 commits into
stack/database-dev-flow/07-apps-initfrom
stack/database-dev-flow/08-db-check

Conversation

@ditadi

@ditadi ditadi commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🥞 Stacked PR (generated by Stack)

Use this link to review incremental changes.


Stacked on #675. The design is #677.

What did you change, and why?

A pull request can break the committed migration history in ways the deployed app finds only on start. appkit db check is an offline check of the committed migrations for CI. It reads only the checkout, so it runs without Databricks or Lakebase credentials, and it takes no history lock. It exits 1, with the fix for each finding, when:

  • config/database/schema.ts changed and no committed migration has the change
  • the journal lists a migration generated before the one ahead of it, which a branch that ran the newer one never runs
  • a snapshot does not follow the one before it, which happens when two migrations were generated from one snapshot on parallel git branches
  • an entry's idx is not its position in the journal, since drizzle-kit names snapshots by idx
  • a migration's .sql or snapshot is not committed, or a .sql is not in the journal
  • a snapshot file is not a drizzle-kit snapshot, because its id or prevId is not a string

The schema comparison is hasUnmigratedChanges in migrations.ts, which shares diffSchema with appkit db migrate. So check fails exactly when migrate would write a migration, and an ambiguous rename counts as a change without a prompt. The comparison runs only when the latest snapshot is a valid drizzle-kit snapshot. Before this revision, a null or {} snapshot skipped both the chain and the schema diff, so check could pass a schema.ts change without a migration.

Two pull requests that both add 0001_migration conflict in git first, and check catches a resolution that keeps both. The fix it names merges the base branch, resets config/database/migrations to the base branch's, then runs appkit db clean and appkit db migrate. The clean is there because the developer's branch already ran the old migration.

database.md lists db check among the commands and among those that take no history lock. Its CI section runs the check on every pull request and explains the conflict. The template README names it.

Review round, 2026-11-09:

  • appkit db check fails on a journal entry whose when is not an integer, a first snapshot not generated from drizzle-kit's empty snapshot, and any snapshot without the v7 PostgreSQL shape.
  • Its conflict recovery tells you to save hand-written SQL and re-add it after regenerating.
  • Docs, --help and the template README say check imports schema.ts (run it in CI without secrets) and does not read the .sql files.

Fix round for fjakobs's review of #677, 2026-11-15:

  • No change of its own. It carries the lower layers' fixes through the merges.

How do you know it works?

  • check.test.ts generates real migration history with drizzle-kit and a real schema.ts, with every Databricks and Lakebase call throwing. It covers a sound history, a schema.ts change without its migration, an ambiguous column rename, a merge that keeps two migrations from one snapshot, a when out of order, an idx that is not its position, uncommitted and unlisted files, and a null and a {} snapshot. The CLI's check.test.ts covers the output and the exit code.
  • The full vitest suite passed against a local PostgreSQL 14. A clean build, the size gate, the docs build and typecheck passed. The packed tarballs export the same root and ./beta names as main, and ./beta/database-tooling adds only runCheck.
  • The template smoke passed with pnpm on a fresh store and with npm.
  • This revision was not run against a real Lakebase workspace. appkit db check makes no Databricks or Lakebase call.

Review round, 2026-11-09: each fix has a failing-then-passing test in its PR, and every layer's appkit and shared tests ran against Postgres 14 after the sync. At the top of the stack, pnpm build, pnpm test (6502 passed, 1 skipped), pnpm -r typecheck, pnpm check, pnpm knip and pnpm docs:build pass.

Fix round for fjakobs's review, 2026-11-15: each fix has a failing-then-passing test in its PR, and every layer's database, plugin and CLI tests ran against Postgres 17 after the sync. A throwaway Lakebase fork confirmed that the developer role can write the service principal's rows but cannot alter its tables. At the top of the stack, pnpm test (6602 passed, 1 skipped), pnpm -r typecheck, pnpm build and pnpm docs:build pass, and oxlint and oxfmt are clean on every changed file.

@ditadi
ditadi force-pushed the stack/database-dev-flow/07-apps-init branch from 7db9fa1 to 81e2e8f Compare October 20, 2026 12:22
@ditadi
ditadi force-pushed the stack/database-dev-flow/08-db-check branch from 8ef366e to 0d6a48a Compare October 20, 2026 12:22
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🤖 AppKit PR bot

🔬 Run evals

Start an eval for this PR from the evals-monitor app: Go to Evals Monitor →

📦 Try this PR's app template

Scaffolds a new app from this PR's SDK build. Run it in any folder (requires the GitHub CLI — gh auth login — and the Databricks CLI):

gh run download 45822406965 -R databricks/appkit -n appkit-template-0.105.0-pr.8dbffb8-stack-database-dev-flow-08-db-check-678 -D appkit-pr-678 \
  && unzip -o "appkit-pr-678/appkit-template-0.105.0-pr.8dbffb8-stack-database-dev-flow-08-db-check-678.zip" -d "appkit-pr-678" \
  && databricks apps init --template "appkit-pr-678"

The template pins @databricks/appkit and @databricks/appkit-ui to tarballs built from this branch, so the scaffolded app runs against this PR's code.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

📦 Bundle size report

Compared against bundle-size-baseline.json (main).

@databricks/appkit

npm tarball (packed): 1.6 MB (+32 KB) — gzipped download (dist + bin; excludes release-only docs/NOTICE).

dist raw gzip
JS (runtime) 1.6 MB (+36 KB) 587 KB (+11 KB)
Type declarations 503 KB (+5.5 KB) 183 KB (+2.0 KB)
Source maps 3.2 MB (+70 KB) 1.1 MB (+21 KB)
Other 11 KB 3.7 KB
Total 5.3 MB (+111 KB) 1.8 MB (+34 KB)
Per-entry composition (own code — deps external (as shipped))
Entry Initial (gz) Lazy (gz) Total (gz) node_modules (min) Own code (min)
. 118 KB (+22 B) 2.4 KB 121 KB (+22 B) external 378 KB (+30 B)
./beta 127 KB (+250 B) 4.6 KB (+25 B) 132 KB (+275 B) external 382 KB (+799 B)
./beta/database-tooling 62 KB (+6.2 KB) 0 B 62 KB (+6.2 KB) external 186 KB (+19 KB)
./testing 47 KB (-2 B) 38 KB (+21 B) 85 KB (+19 B) external 246 KB (+30 B)
./tsdown 630 B 0 B 630 B external 1.0 KB
./type-generator 31 KB (+25 B) 0 B 31 KB (+25 B) external 89 KB (+30 B)

Chunks:

Entry Chunk Load Size (gz)
. index.js initial 114 KB
. utils.js initial 4.6 KB
. remote-tunnel-manager.js lazy 2.4 KB
./beta beta.js initial 101 KB
./beta stream-manager.js initial 5.9 KB
./beta define-schema.js initial 5.9 KB
./beta service-context.js initial 4.3 KB
./beta modular.js initial 3.6 KB
./beta databricks.js initial 3.3 KB
./beta wide-event-emitter.js initial 2.8 KB
./beta client.js initial 645 B
./beta index.js initial 20 B
./beta index.js lazy 4.1 KB
./beta supervisor-api.js lazy 201 B
./beta databricks.js lazy 188 B
./beta index.js lazy 124 B
./beta/database-tooling index.js initial 62 KB
./testing manifest.js initial 33 KB
./testing index.js initial 10 KB
./testing wide-event-emitter.js initial 2.9 KB
./testing index.js lazy 34 KB
./testing remote-tunnel-manager.js lazy 2.4 KB
./testing utils.js lazy 1.8 KB
./tsdown index.js initial 630 B
./type-generator index.js initial 31 KB

@databricks/appkit-ui

npm tarball (packed): 393 KB — gzipped download (dist + bin; excludes release-only docs/NOTICE).

dist raw gzip
JS (runtime) 430 KB 146 KB
Type declarations 250 KB 93 KB
Source maps 837 KB 281 KB
CSS 16 KB 3.2 KB
Total 1.5 MB 522 KB
Per-entry composition (consumer bundle — deps bundled, peerDeps external)
Entry Initial (gz) Lazy (gz) Total (gz) node_modules (min) Own code (min)
./js 5.3 KB 49 KB 55 KB 208 KB 14 KB
./js/beta 2.4 KB 0 B 2.4 KB 0 B 5.3 KB
./react 441 KB 49 KB 489 KB 1.4 MB 180 KB
./react/beta 13 KB 0 B 13 KB 25 KB 13 KB

Chunks:

Entry Chunk Load Size (gz)
./js index.js initial 5.2 KB
./js chunk initial 120 B
./js apache-arrow lazy 49 KB
./js/beta beta.js initial 2.4 KB
./react index.js initial 439 KB
./react tslib initial 2.1 KB
./react apache-arrow lazy 49 KB
./react/beta beta.js initial 13 KB

ditadi added a commit that referenced this pull request Oct 30, 2026
The design doc promised behavior the corrected stack does not ship. It
now describes what the code does:

- The tooling export is @databricks/appkit/beta/database-tooling, beta
  and internal to the AppKit CLI.
- migrate, introspect, clean and init hold config/database/.appkit-db.lock.
  init holds one lock for its whole run, and init --schema none, seed,
  verify and clean --delete-branch take none. The doc says how to
  recover a stale lock file.
- init --schema none hands off nothing, and schema public is never
  handed off.
- Values in variable-overrides.json count for the deploy boundary, and
  an unresolved branch or database reference refuses every write.
- Introspect keeps .private() on declared columns, writes new columns
  private, and refuses a schema.ts that does not load or a foreign key
  it does not declare.
- verify --deployed compares the committed migrations with the source
  snapshot of the active deployment, and fails when it cannot read it.
- Migrations log one line per run. There is no span and no metric.
- #675 keeps the plugin and appkit db hidden. A reveal is a later,
  separate change.

The appkit db check section stays as it is until #678 settles.

Signed-off-by: ditadi <victordperd@gmail.com>
ditadi and others added 16 commits November 9, 2026 13:55
A fork of the deploy branch carries every row of its source, production data
included, and init migrated it as it stood. Without --schema, a branch init
forked in this run now gets clean as its start when schema.ts exists, and
introspect followed by a rebuild from the baseline it wrote when it does not.
A reused branch keeps its data: migrate, or introspect without schema.ts.
--schema migrate, or --schema introspect, keeps the copied rows on a new fork.
In public, clean removes only your objects, and the report lists what stayed.

Before the fork, init writes APPKIT_DB_NEW_BRANCH=<branch> to .env and removes
it when the start completes, so a run that stops during or after the fork is
finished by its rerun instead of migrating the copied rows into place. A fork
refused for permissions or the branch limit removes the marker again.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
For an introspect start, init read the hand-off's schema as the default name
even when schema.ts declared another, and let introspect read the default too.
Both now use the declared name whenever schema.ts exists; --schema none still
reads no schema.ts.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
introspect's refusal for a schema without tables says to pass --schema-name,
a flag init does not have. When init relays it, the advice now says to run
`appkit db introspect --schema-name <name>`.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…branch

The help said a new branch starts with a copy of the default branch's rows.
It now says init rebuilds the app schema from the migrations so the branch
starts without them, how --schema migrate or introspect keeps them, and that a
reused branch is migrated. The report prints why a default run dropped the
schema, with the flag that keeps the rows, prints the introspect, drop and
migrations of an introspect start with a rebuild, and no longer says a rebuilt
branch keeps its approximated objects.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
readDeployTarget reads #666's flattened postgres bindings ({ at, value }),
pairing the branch with the database written in the same postgres block.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
env-file kept its own temp-file-and-rename copy; it now uses files.ts with
mode 0600, and its symlink refusal builds on the shared check.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
… clean

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…e reader

The fail-closed fix flattened each resource into separate branch and
database values; keep one PostgresBinding per resource (with a whole
marker for a ${…} standing in for the structure), which later readers
that count an app's resources need.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
readDeployTarget reads #666's per-resource postgres bindings again.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
Co-authored-by: Isaac <no-reply@databricks.com>
verify keeps one postgres binding per resource and reads app names next to
#666's unresolved-structure markers; its test fakes answer #654's journal
check and #655's shared tables-in-public lookup.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…ed migrations

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
ditadi and others added 26 commits November 25, 2026 18:07
…se-dev-flow/08-db-check

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…urce name

A value with text around projects/<p>/branches/<b>/endpoints/<e> named a branch
the refusal of dev and session branches then checked, though the value is not
the app's endpoint. Anchor the match so such a value is refused as naming no
branch.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
Name the LAKEBASE_ENDPOINT resource name that migrate on start reads the
branch from, and that a start without the flag or the app's identity skips the
refusal with the migration.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…tack/database-dev-flow/02-default-app-schema

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…ck/database-dev-flow/03-db-migrate

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…signal

On SIGINT or SIGTERM the lock was released even when another listener kept
the process running, so the command went on writing the history after another
command could take the lock. Release and re-raise only when the lock's handler
is the one ending the process; otherwise the exit listener releases it.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
A route module that failed to load made migrate fail after it had written the
new migration, without saying it kept the file or what the migration warns
about. Write database.d.ts and database-operations.d.ts first, so that failure
stops migrate before it writes anything; the types still follow schema.ts when
applying fails.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
loadDatabaseSchema kept the raw import error as the cause for every caller,
including the development start that main keeps to a bounded message. The
cause is now attached only when the caller passes showImportError, which only
the db CLI does.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
SIGINT and SIGTERM release it only when nothing else handles the signal, and
any other way of ending can leave the file for the next command to report.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…ase-dev-flow/04-db-introspect

# Conflicts:
#	packages/appkit/src/database/tooling/migrate.ts

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
loadDatabaseSchema now keeps the import error only for a caller that asks, so
introspect asks for it when it loads the schema.ts it replaces and the one it
generates.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…tabase-dev-flow/05-db-init

# Conflicts:
#	packages/appkit/src/database/tooling/migrate.ts

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…d seed

loadDatabaseSchema now keeps the import error only for a caller that asks, so
the commands that read the app schema from schema.ts ask for it.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
The warning about the bound database, the step that points .env at the branch,
the hand-off messages and the report the CLI prints carried the Postgres
database name raw, so a name with a control character reached the terminal.
Pass them through shown(); .env and the connections keep the raw name.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…ed tests

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…-dev-flow/06-db-verify

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
loadDatabaseSchema now keeps the import error only for a caller that asks, so
verify asks for it when it reads schema.ts.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
verify escaped the apps API message in its error but kept the raw error as
the cause, and the CLI prints the innermost cause as is, so control characters
in the API's text reached the terminal. Throw the escaped error alone.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
An included file's source_code_path was joined to the file's folder before its
${var.…} references resolved, so a variable naming an absolute path became
resources/<path>. Keep the path with its file's folder and rebase only a
relative result once it resolves; an absolute one stays as it is and an
unresolved one stays as written.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…se-dev-flow/07-apps-init

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…se-dev-flow/08-db-check

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
loadDatabaseSchema now keeps the import error only for a caller that asks, so
check asks for it when it compares schema.ts with the latest snapshot.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
CI sets CI, so picocolors colors the warning marker and the assertion on
"! Could not mark ..." failed there while it passed in a local shell.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…-dev-flow/06-db-verify

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…se-dev-flow/07-apps-init

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…se-dev-flow/08-db-check

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
@ditadi
ditadi removed this pull request from stack #667 November 26, 2026 14:50
@ditadi
ditadi force-pushed the stack/database-dev-flow/07-apps-init branch from 7aa8416 to 2032d58 Compare November 26, 2026 14:51
@ditadi

ditadi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Folded into #666. The database development flow stack is now three PRs: #654 (runtime), #666 (appkit db commands) and #675 (template and docs). appkit db check ships in #666 unchanged. The branch stays for reference.

This comment was written by Isaac.

@ditadi ditadi closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant